﻿using iChip.Hotspots.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace iChip.Hotspots.Controllers
{
    public class HomeController : Controller
    {
        private BO.BOs _bo = new BO.BOs();
        public ActionResult Index(string called, string mac, int? user_type)
        {
            //"30-B5-C2-D5-E0-8F" E4-D5-3D-08-1D-05
            if(string.IsNullOrEmpty(called))
            {
                called = "30-B5-C2-D5-E0-8F";
            }

            if (string.IsNullOrEmpty(mac))
            {
                mac = "E4-D5-3D-08-1D-05";
            }
            var model = new IndexObject();
            model = _bo.Get_Field_by_Hotspot_Mac(called, user_type.GetValueOrDefault());
            ViewBag.Mac = mac;
            return View(model);
        }
        

        public ActionResult TestDropdownlist()
        {
            var model = new List<FieldTypeId>();
            IEnumerable<iChip.Hotspots.Commons.Enums.FieldType> fieldType = Enum.GetValues(typeof(iChip.Hotspots.Commons.Enums.FieldType)).Cast<iChip.Hotspots.Commons.Enums.FieldType>();

            for (int i = 1; i <= 7; i++)
            {
                model.Add(new FieldTypeId
                {
                    Field_Id = i,
                    Field_Type = fieldType.Select(m => new SelectListItem
                    {
                        Text = m.ToString(),
                        Value = ((int)m).ToString()
                    }).ToList()
                });
            }
            //for (int i = 1; i <= 7; i++)
            //{
            //    model.Field_Ids.Add(new FieldTypeId
            //    {
            //        Field_Id = i,
            //        Field_Type = fieldType.Select(m => new SelectListItem
            //        {
            //            Text = m.ToString(),
            //            Value = ((int)m).ToString()
            //        }).ToList()
            //    });
            //}

            return View(model);
        }

        [HttpPost]
        public ActionResult PostInfo(List<RequestPostField> objRequest, string mac)
        {
            _bo.Insert_Values(mac, objRequest);
            return new JsonResult();
        }
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult FieldCreate(int method_id)
        {
            ViewBag.MethodId = method_id;
            return View();
        }

        [HttpPost]
        public ActionResult FieldCreated(List<RequestPostField> objRequest, List<FieldValue> objRequestFieldValue)
        {

            _bo.Insert_Fields(objRequest, objRequestFieldValue);
            return new JsonResult();
        }

        public ActionResult GenField()
        {
            var model = new FieldCreate();
            return PartialView(model);
        }

        public ActionResult TestDatetimePicker()
        {
            return View();
        }
    }

    public class FieldTypeId
    {
        public FieldTypeId()
        {
            Field_Type = new List<SelectListItem>();
        }

        public int Field_Id { get; set; }
        public IEnumerable<SelectListItem> Field_Type { get; set; }   
    }

    public class FieldTypeTest
    {
        public FieldTypeTest()
        {
            //Field_Type = new List<SelectListItem>();
            Field_Ids = new List<FieldTypeId>();
        }
        public List<FieldTypeId> Field_Ids { get; set; }
        //public IEnumerable<SelectListItem> Field_Type { get; set; }   
        
    }

    public class FieldType
    {
        public FieldType()
        {
            Field_Type = new List<SelectListItem>();
        }

        public IEnumerable<SelectListItem> Field_Type { get; set; }   
    }

}